% fig1a_phase_diagram.m — 调用封装函数 Logistic 绘制 Fig.1(a) 相图
clc; clear; close all;

% ——— 参数设置 ———
x0       = 0.463442265;    % 初始 x
y0       = 0.04532285;     % 初始 y
z0       = 0.002136285;    % 初始 z
gamma    = 3.99;           % 分岔参数 γ，对应 Fig.1(a)
b        = 30;             % 耗散参数 β
Ntrans   = 500;            % 丢弃前 Ntrans 步暂态
Nphase   = 5000;           % 相图记录后续 Nphase 步

% ——— 预分配存储 ———
x_vals = zeros(Nphase,1);
y_vals = zeros(Nphase,1);
z_vals = zeros(Nphase,1);

% ——— 迭代 —— 
x = x0;    y = y0;    z = z0;
x_prev = x;  z_prev = z;
for k = 1 : (Ntrans + Nphase)
    % 调用封装好的单步迭代函数
    [x_new, y_new, z_new] = Logistic(x, y, z, x_prev, z_prev, gamma, b);
    
    % 更新前后状态
    x_prev = x;
    z_prev = z;
    x = x_new;
    y = y_new;
    z = z_new;
    
    % 记录相图数据
    if k > Ntrans
        idx = k - Ntrans;
        x_vals(idx) = x;
        y_vals(idx) = y;
        z_vals(idx) = z;
    end
end

% ——— 绘制 3D 相图 ———
figure;
plot3(x_vals, y_vals, z_vals, '.', 'MarkerSize', 1);
view(45, 25);
xlabel('x', 'FontSize', 12);
ylabel('y', 'FontSize', 12);
zlabel('z', 'FontSize', 12);
title('Fig.1(a) Phase Diagram (\gamma=3.99, \beta=30)', 'FontSize', 14);
axis tight; box on;
